<?php

namespace Loan\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class BalanceController extends AbstractActionController
{
    protected $balanceTable;
    protected $balance;
    protected $loan_id;

    public function __construct($loan_id = null)
    {
        $this->loan_id = $loan_id;
    }

    public function getBalanceTable()
    {
        if (!$this->balanceTable) {
            $sm = $this->getServiceLocator();
            $this->balanceTable = $sm->get('Balance\Model\BalanceTable');
        }
        return $this->balanceTable;
    }

    public function indexAction()
    {
        $this->loan_id = $this->params()->fromRoute('id', null);
        $this->balance = $this->getBalanceTable()->getBalanceByLoanId($this->loan_id);
        $view = new ViewModel(array(
            'balance' => $this->balance
        ));
        return $view;
    }
}